import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
import { useUserStoreWithOut } from '/@/store/modules/user';
import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/oauth/token',
  Logout = '/oauth/removeToken',
  GetUserInfo = '/user/queryPermission',
  GetPermCode = '/getPermCode',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
      auth: {
        username: 'innovate-admin',
        password: '678283c2-6d6f-4f5e-9b59-b1a1fa1b2692',
      }
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  const userStore = useUserStoreWithOut();
  console.log('userStore', userStore.getClientId);
  return defHttp.post({ url: Api.GetUserInfo, headers: { 'clientId': userStore.getClientId } }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.post({ url: Api.Logout});
}
